home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / ida / aux / header.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-01  |  1.9 KB  |  104 lines

  1. /*
  2. **  HEADER -- Header line parser.
  3. **  Copyright (c) 1985 Lennart Lovstrand
  4. **  CIS Dept, Univ of Linkoping, Sweden
  5. **
  6. **  Use it, abuse it, but don't sell it.
  7. **
  8. **  Version of 14-Apr-85.
  9. */
  10.  
  11. #include "sendmail.h"
  12.  
  13. #define HH_CC        "cc"
  14. #define HH_FROM        "from"
  15. #define HH_MESSAGE_ID    "message_id"
  16. #define HH_RETURN_PATH    "return-path"
  17. #define HH_TO        "to"
  18. #define HH_VIA        "via"
  19.  
  20. #define COMMA    ','
  21.  
  22. #define MAKELC(C)    (isupper(C) ? tolower(C) : C)
  23.  
  24. #ifndef lint
  25. static char    Rcsid[] = "@(#)$Id: header.c,v 1.4 1991/07/01 17:28:32 paul Exp $";
  26. #endif /* !lint */
  27.  
  28. #ifdef __STDC__
  29. int iskey(const char *, const char *);
  30. char * eat(char *, int);
  31. char * extract_address(char *, char *);
  32. #else /* !__STDC__ */
  33. # define    const
  34. int iskey();
  35. char * eat();
  36. char * extract_address();
  37. #endif /* __STDC__ */
  38.  
  39. /*
  40.  *    iskey: checks if the line is prefixed by
  41.  *    the supplied keyword (immediately followed by
  42.  *    a colon)
  43.  */
  44. iskey(key, line)
  45.     const char *key, *line;
  46. {
  47.     for (; *key != NULL && *line != NULL; key++, line++)
  48.         if (MAKELC(*key) != MAKELC(*line))
  49.             break;
  50.  
  51.     return *key == NULL && *line == ':';
  52. }
  53.  
  54. char *
  55. eat(str, ch)
  56.     char *str, ch;
  57. {
  58.     for(; *str == ch; str++);
  59.     return str;
  60. }
  61.  
  62. /*
  63.  *    extract_address:
  64.  *    finds and extracts the machine address part of an address field
  65.  */
  66.  
  67. char *
  68. extract_address(field, address)
  69.     char *field, *address;
  70. {
  71.     char *address_start = address;
  72.  
  73.     while(*field && *field != COMMA && *field != '>')
  74.         switch (*field) {
  75.             case '<':
  76.                 return extract_address(field, address_start);
  77.             case '(':
  78.                 while (*field && *field != ')');
  79.                     field++;
  80.                 break;
  81.             case '"':
  82.                 do
  83.                     *address++ = *field++;
  84.                 while (*field && *field != '"');
  85.                 if (*field)
  86.                     *address++ = *field++;
  87.                 break;
  88.             case ' ':
  89.                 *address++ = *field++;
  90.                 field = eat(field, ' ');
  91.                 break;
  92.             case '\\':
  93.                 *address++ = *field++;
  94.                 /* fall through */
  95.             default:
  96.                 *address++ = *field++;
  97.         }
  98.     *address = NULL;
  99.     if (*field)
  100.         return index(field, COMMA)+1;
  101.     else
  102.         return field;
  103. }
  104.